home *** CD-ROM | disk | FTP | other *** search
/ PC go! 2008 April / PCgo 2008-04 (DVD).iso / interface / contents / demoversionen_3846 / 13664 / files / Data1.cab / sdkdemoppg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2006-05-31  |  5.4 KB  |  192 lines

  1. /******************************************************************/
  2. /*                                                                */
  3. /*                      TurboCAD for Windows                      */
  4. /*                   Copyright (c) 1993 - 2001                    */
  5. /*             International Microcomputer Software, Inc.         */
  6. /*                            (IMSI)                              */
  7. /*                      All rights reserved.                      */
  8. /*                                                                */
  9. /******************************************************************/
  10.  
  11. // SDKDemoPpg.cpp : Implementation of the CSDKDemoPropPage property page class.
  12.  
  13. #include "stdafx.h"
  14. #include "SDKDemo.h"
  15. #include "SDKDemoPpg.h"
  16.  
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22.  
  23.  
  24. IMPLEMENT_DYNCREATE(CSDKDemoPropPage, COlePropertyPage)
  25.  
  26.  
  27. /////////////////////////////////////////////////////////////////////////////
  28. // Message map
  29.  
  30. BEGIN_MESSAGE_MAP(CSDKDemoPropPage, COlePropertyPage)
  31.     //{{AFX_MSG_MAP(CSDKDemoPropPage)
  32.     ON_BN_CLICKED(IDC_FILE_BROWSE, OnFileBrowse)
  33.     ON_BN_CLICKED(IDC_LAYER_REFRESH, OnLayerRefresh)
  34.     ON_BN_CLICKED(IDC_LAYER_SHOW_ALL, OnLayerShowAll)
  35.     //}}AFX_MSG_MAP
  36. END_MESSAGE_MAP()
  37.  
  38.  
  39. /////////////////////////////////////////////////////////////////////////////
  40. // Initialize class factory and guid
  41.  
  42. IMPLEMENT_OLECREATE_EX(CSDKDemoPropPage, "SDKDEMO.SDKDemoPropPage.1",
  43.     0xa63e6665, 0xc85f, 0x11d0, 0x9b, 0x3b, 0x44, 0x45, 0x53, 0x54, 0, 0)
  44.  
  45.  
  46. /////////////////////////////////////////////////////////////////////////////
  47. // CSDKDemoPropPage::CSDKDemoPropPageFactory::UpdateRegistry -
  48. // Adds or removes system registry entries for CSDKDemoPropPage
  49.  
  50. BOOL CSDKDemoPropPage::CSDKDemoPropPageFactory::UpdateRegistry(BOOL bRegister)
  51. {
  52.     if (bRegister)
  53.         return AfxOleRegisterPropertyPageClass(AfxGetInstanceHandle(),
  54.             m_clsid, IDS_SDKDEMO_PPG);
  55.     else
  56.         return AfxOleUnregisterClass(m_clsid, NULL);
  57. }
  58.  
  59.  
  60. /////////////////////////////////////////////////////////////////////////////
  61. // CSDKDemoPropPage::CSDKDemoPropPage - Constructor
  62.  
  63. CSDKDemoPropPage::CSDKDemoPropPage() :
  64.     COlePropertyPage(IDD, IDS_SDKDEMO_PPG_CAPTION)
  65. {
  66.     //{{AFX_DATA_INIT(CSDKDemoPropPage)
  67.     m_strFileName = _T("");
  68.     //}}AFX_DATA_INIT
  69. }
  70.  
  71.  
  72. /////////////////////////////////////////////////////////////////////////////
  73. // CSDKDemoPropPage::DoDataExchange - Moves data between page and properties
  74.  
  75. void CSDKDemoPropPage::DoDataExchange(CDataExchange* pDX)
  76. {
  77.     //{{AFX_DATA_MAP(CSDKDemoPropPage)
  78.     DDX_Control(pDX, IDC_VISIBLE_LAYERS, m_lbLayers);
  79.     DDP_Text(pDX, IDC_FILE_NAME, m_strFileName, _T("FileName") );
  80.     DDX_Text(pDX, IDC_FILE_NAME, m_strFileName);
  81.     DDV_MaxChars(pDX, m_strFileName, 256);
  82.     //}}AFX_DATA_MAP
  83.  
  84.     CString strLayers;
  85.     DDP_Text(pDX, IDC_VISIBLE_LAYERS, strLayers, _T("HideLayers"));
  86.  
  87.     if (!pDX->m_bSaveAndValidate)
  88.         OnLayerRefresh();
  89.     int nTotalCount = m_lbLayers.GetCount();
  90.     int* rgSel = new int[nTotalCount > 0 ? nTotalCount : 1];
  91.     if (pDX->m_bSaveAndValidate)
  92.     {
  93.         int nSelCount = m_lbLayers.GetSelItems(nTotalCount, rgSel);
  94.         for (int i = 0; i < nSelCount; ++i)
  95.         {
  96.             CString str;
  97.             m_lbLayers.GetText(rgSel[i], str);
  98.             if (!str.IsEmpty())
  99.             {
  100.                 if (!strLayers.IsEmpty())
  101.                     strLayers += "\n";
  102.                 strLayers += str;
  103.             }
  104.         }
  105.     }
  106.     else
  107.     {
  108.         int i = 0;
  109.         for (i = 0; i < nTotalCount; ++i)
  110.             m_lbLayers.SetSel(i, FALSE);
  111.         for (i = 0; ; ++i)
  112.         {
  113.             CString str;
  114.             if (!AfxExtractSubString(str, strLayers, i, '\n'))
  115.                 break;
  116.             if (!str.IsEmpty())
  117.             {
  118.                 int nFind = m_lbLayers.FindStringExact(-1, str);
  119.                 if (nFind < 0)
  120.                     nFind = m_lbLayers.AddString(str);
  121.                 if (nFind >= 0)
  122.                     m_lbLayers.SetSel(nFind, TRUE);
  123.             }
  124.         }
  125.     }
  126.     delete [] rgSel;
  127.     DDP_PostProcessing(pDX);
  128. }
  129.  
  130.  
  131. /////////////////////////////////////////////////////////////////////////////
  132. // CSDKDemoPropPage message handlers
  133.  
  134. void CSDKDemoPropPage::OnFileBrowse() 
  135. {
  136.     static TCHAR BASED_CODE szFilter[] = _T("TurboCAD Drawing Files (*.tcw)|*.tcw|All Files (*.*)|*.*||");
  137.     CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, this);
  138.     if (dlg.DoModal() == IDOK && !dlg.GetPathName().IsEmpty())
  139.     {
  140.         m_strFileName = dlg.GetPathName();
  141.         CDataExchange dx(this, FALSE);
  142.         CDataExchange* pDX = &dx;
  143.         DDX_Text(pDX, IDC_FILE_NAME, m_strFileName);
  144.     }
  145. }
  146.  
  147. void CSDKDemoPropPage::OnLayerRefresh() 
  148. {
  149.     COleDispatchDriver PropDispDriver; 
  150.     ULONG nObjects;
  151.     LPDISPATCH* ppDisp = GetObjectArray(&nObjects);
  152.     for (ULONG i = 0; i < nObjects; i++) 
  153.     { 
  154.         DISPID dwDispID; 
  155.         LPCOLESTR lpOleStr = OLESTR("AllLayers");
  156.         if (SUCCEEDED(ppDisp[i]->GetIDsOfNames(IID_NULL, (LPOLESTR*)&lpOleStr, 1, 0, &dwDispID))) 
  157.         { 
  158.             CString strLayers; 
  159.             PropDispDriver.AttachDispatch(ppDisp[i], FALSE); 
  160.             PropDispDriver.GetProperty(dwDispID, VT_BSTR, &strLayers); 
  161.             PropDispDriver.DetachDispatch();
  162.             for (int j = 0; ; ++j)
  163.             {
  164.                 CString str;
  165.                 if (!AfxExtractSubString(str, strLayers, j, '\n'))
  166.                     break;
  167.                 if (!str.IsEmpty())
  168.                 {
  169.                     int nFind = m_lbLayers.FindStringExact(-1, str);
  170.                     if (nFind < 0)
  171.                         nFind = m_lbLayers.AddString(str);
  172.                 }
  173.             }
  174.         } 
  175.     } 
  176. }
  177.  
  178. void CSDKDemoPropPage::OnLayerShowAll() 
  179. {
  180.     if (m_hWnd != NULL)
  181.     {
  182.         OnLayerRefresh();
  183.         int nCount = m_lbLayers.GetCount();
  184.         for (int i = 0; i < nCount; ++i)
  185.         {
  186.             m_lbLayers.SetSel(i, FALSE);
  187.         }
  188.     }
  189.     SetModifiedFlag();
  190. }
  191.  
  192.